package com.rabbit.videoplayer.dialog.gesturedialog;

import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;

import com.rabbit.videoplayer.R;


/*
 * Copyright (C) 2010-2018 Alibaba Group Holding Limited.
 */

/**
 * 手势滑动的音量提示框。
 */
public class VolumeDialog extends BaseGestureDialog {

    private static final String TAG = VolumeDialog.class.getSimpleName();
    public float currentVolume = 0;

    public VolumeDialog(Activity context) {
        super(context);
        AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        int max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        currentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        float percent = currentVolume * 100 / max;
        mImageView.setImageResource(R.drawable.bg_wb_mix_vlomue_change);
        updateVolume(percent);
    }

    /**
     * 更新音量值
     * @param percent 音量百分比
     */
    public void updateVolume(float percent) {
        String percentStr = (int)percent + "%";
        mTextView.setText(percentStr);
        mImageView.setImageLevel((int) percent);
    }

    /**
     * 获取最后的音量
     * @param changePercent 变化的百分比
     * @return 最后的音量
     */
    public float getTargetVolume(int changePercent) {
        return changePercent;
    }
}
